﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="EditMovimentoCaricoCliente.aspx.cs" Inherits="FimetContoDeposito.Cliente.EditMovimentoCaricoCliente" %>

<%@ Register assembly="GrayParrot.Web.Controls" namespace="GrayParrot.Web.Controls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">        
        <%: Scripts.Render("~/bundles/JQuery") %>          
        <%: Scripts.Render("~/bundles/JQueryUI") %>  
        <%: Styles.Render("~/bundles/Formly/css") %>
        <%: Scripts.Render("~/bundles/Formly") %>
		
        <%: Styles.Render("~/bundles/Datatables/css") %>
        <%: Scripts.Render("~/bundles/Datatables") %>
    </asp:PlaceHolder>

    <!-- Common -->
    <script type="text/javascript" lang="javascript" src="../Scripts/Formly/FormlyHelper.js"></script>
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.Fileupload.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.DateTimePicker.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.DataTables.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Modals.js"></script> 

    <script type="text/javascript" lang="javascript" src="../Scripts/jquery.blockUI.js"></script> 

    <script type="text/javascript" lang="javascript" src="../Scripts/FCD.js"></script> 
    <!-- Common -->
</asp:Content>

<asp:Content ID="ContentSH" ContentPlaceHolderID="specialHead" runat="server">
    <style>
        .col-xs-4
        {
            padding:2px;
        }
        .col-xs-3
        {
            padding:2px;
        }
        .col-xs-10
        {
            padding:1px;
        }
        .col-xs-12
        {
            padding:1px;
        }
        .form-control
        {
            font-size:14px;
            padding:2px;
        }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <section class="panel">
	    <header class="panel-heading">
			<b>Modifica Movimento Carico</b>
		</header>

        <iframe id='iframeCrud' frameborder="0" style="width:700px; height:600px; display:none"></iframe>
        <div id="crudDialog" title="" style="display:none"></div>

		<div class="panel-body">
            <!-- PUT YOUR CONTENT HERE -->
            <div class="row">

			   <div class="col-md-6">
                    <div class="row">
                        <cc1:JQDataTable ID="JQDTMovimentiCaricoCliente" runat="server" 
                                SelectionMode="Single" 
                                RenderScripts="false" 
                                IsResponsive="true"
                                BootstrapClasses="table table-hover table-bordered table-condensed" Width="98%">
                            <FeaturesConfig>
                                <Features>
                                    <cc1:Searching Value="none" />
                                    <cc1:AutoWitdh Value="true" />
                                    <cc1:ScrollY Value="400" ScrollCollapse="true" />
                                    <cc1:LengthChange Value="false" />
                                    <%--<cc1:Paging PagingType="FullNumbers" PageLength="20" />--%>
                                </Features>
                            </FeaturesConfig>
                            <ControllerConfig Url="/api/MovimentiCliente/LoadMovimentiClienteNonEvasi" LoadingMode="OnLoad" />
                            <ColumnsConfig Key="Id">
                                <Columns>
                                    <cc1:TextColumn Name="Id" Header="Id" Visible="false" />
                                    <cc1:TextColumn Name="NumeroDDT" Header="NumeroDdt" />
                                    <cc1:DateColumn Name="DataDDT" Header="Data" />
                                    <cc1:TextColumn Name="IdCliente" Header="Id Cliente" Visible="false" />
                                    <cc1:TextColumn Name="Cliente" Header="Cliente" />
                                    <cc1:TextColumn Name="Fornitore" Header="Fornitore" />
                                    <cc1:ActionColumn >
                                        <Actions>
                                            <cc1:ActionIcon Icon="fa fa-search" Callback="MostraDettaglio" />
                                            <cc1:ActionIcon Icon="fa fa-trash-o" Callback="CancellaOrdine" />
                                        </Actions>
                                    </cc1:ActionColumn>
                                </Columns>
                            </ColumnsConfig>
                            <Toolbar>
                                <cc1:IconButton Icon="fa fa-trash-o" Callback="CancellaOrdini" />
                            </Toolbar>
                        </cc1:JQDataTable>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="row">
                        <cc1:JQDataTable ID="JQDTDettaglioMovimentiCaricoCliente" runat="server" 
                                SelectionMode="Single" 
                                RenderScripts="false" 
                                IsResponsive="true"
                                BootstrapClasses="table table-hover table-bordered table-condensed">
                            <FeaturesConfig>
                                <Features>
                                    <cc1:Searching Value="none" />
                                    <cc1:AutoWitdh Value="true" />
                                    <cc1:ScrollY Value="400" ScrollCollapse="true" />
                                    <cc1:LengthChange Value="false" />
                                    <%--<cc1:Paging PagingType="FullNumbers" PageLength="20" />--%>
                                </Features>
                            </FeaturesConfig>
                            <ControllerConfig Url="/api/MovimentiCliente/LoadMovimentiClienteNonEvasiDetails" LoadingMode="Redraw">
                                <ControllerParameters>
                                    <cc1:ControllerParameter Name="IdMovimento" Eval="GetIdMovimento" />
                                </ControllerParameters>    
                            </ControllerConfig>
                            <ColumnsConfig Key="IdMovimento">
                                <Columns>
                                    <cc1:TextColumn Name="IdMovimento" Header="Id" Visible="false" />
                                    <cc1:TextColumn Name="IdArticolo" Header="IdArticolo" visible="false" />
                                    <cc1:TextColumn Name="CodiceArticolo" Header="Articolo" />
                                    <cc1:TextColumn Name="CodiceFornitore" Header="Fornitore" />
                                    <cc1:NumericColumn Name="QtaGrz" Header="Quantita" />
                                    <cc1:TextColumn Name="UMgrz" Header="U.M." />
                                    <cc1:ActionColumn >
                                        <Actions>
                                            <cc1:ActionIcon Icon="fa fa-search" Callback="ShowImage" />
                                            <cc1:ActionIcon Icon="fa fa-edit" Callback="ModificaMovimento" />
                                            <cc1:ActionIcon Icon="fa fa-trash-o" Callback="CancellaDettaglio" />
                                        </Actions>
                                    </cc1:ActionColumn>
                                </Columns>
                            </ColumnsConfig>
                            <Toolbar>
                                <cc1:IconButton Icon="fa fa-print" Callback="Stampa" />
                            </Toolbar>
                        </cc1:JQDataTable>
                    </div>
                </div>
            </div>
		</div>

	</section>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="LocaJavascript" runat="server">
    <% HttpContext.Current.Response.Write(this.JQDTMovimentiCaricoCliente.RenderScriptsManually()); %>
    <% HttpContext.Current.Response.Write(this.JQDTDettaglioMovimentiCaricoCliente.RenderScriptsManually()); %>

<script type="text/javascript">
    $(document).ready(function () {
        m_tableJQDTMovimentiCaricoCliente.order([1, 'asc']).draw();
        m_tableJQDTDettaglioMovimentiCaricoCliente.order([1, 'asc']).draw();

        /* imposto blockUI in modo da avere il messaggio per le operazioni di cancellazione */
        $.blockUI.defaults.message = 'Cancellazione in corso...';
        $(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);

        /* 
        imposto ajax global a false in modo che il blocco non influisca sulle operazioni ajax standard, tipo il load.
        Sulle specifiche operazioni su cui blockUI deve intervenire per bloccare la UI, bisogna quindi impostare ajax global a true
        */
        $.ajaxSetup({
            global : false
        });
    });

    var m_rowPosition = 1;
    var m_id_movimento_carico = null;
    var m_dialog = null;
    var m_movimento = null;

    function MostraDettaglio(obj) {
        m_movimento = obj;

        m_tableJQDTDettaglioMovimentiCaricoCliente.rows().draw();
    }

    function GetIdMovimento() {
        if ((m_movimento == null) || (m_movimento === undefined)) {
            return "";
        }
        return m_movimento.Id;
    }

    function ModificaMovimento(obj) {
        var p = obj.IdMovimento;

        window.location.replace('/Cliente/Carico.aspx?Id=' + p)
    }

    function dialogClose() {
        $("#iframeCrud").contents().remove();
        $('#crudDialog').hide();

        $("#crudDialog").dialog("close");
    }

    /* cancella tutti gli ordini non evasi presenti */
    function CancellaOrdini(obj) {
        var url = "/api/MovimentiCliente/CancellaOrdiniNonEvasi";

        $.ajax({
            global: true,
            type: "POST",
            url: url,
            data: null,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                RedrawGrid(m_tableJQDTMovimentiCaricoCliente);
                Empty(m_tableJQDTDettaglioMovimentiCaricoCliente);

                alert(response);
            },
            failure: function (response) {
                alert(response);
            }
        });
    }

    /* cancella un ordine non evaso */
    function CancellaOrdine(obj) {
        var url = "/api/MovimentiCliente/CancellaOrdineNonEvaso";

        var m_data = JSON.stringify({ Id: obj.Id });
        $.ajax({
            global: true,
            type: "POST",
            url: url,
            data: m_data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                RedrawGrid(m_tableJQDTMovimentiCaricoCliente);
                Empty(m_tableJQDTDettaglioMovimentiCaricoCliente);

                alert(response);
            },
            failure: function (response) {
                alert(response);
            }
        });
    }

    function CancellaDettaglio(obj) {
        var url = "/api/MovimentiCliente/CancellaDettaglioOrdineNonEvaso";

        var m_data = JSON.stringify({ Id: obj.IdMovimentoDettaglio });
        $.ajax({
            global: true,
            type: "POST",
            url: url,
            data: m_data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                RedrawGrid(m_tableJQDTMovimentiCaricoCliente);
                Empty(m_tableJQDTDettaglioMovimentiCaricoCliente);

                alert(response);
            },
            failure: function (response) {
                alert(response);
            }
        });
    }

    function Stampa() {
        if ((m_id_movimento_carico == null) || (m_id_movimento_carico === undefined)) {
            alert('Nessun movimento di carico presente...');
            return;
        }

        var url = '/OperationReports/ReportTest.aspx?id=' + m_id_movimento_carico;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Movimento di Carico',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function (response) {
                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }
</script>
</asp:Content>